Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Making run-time references with DYNAMIC-FUNCTION
Progress lets you construct a reference to a function at run time, using a built-in function called
DYNAMIC-FUNCTION. Here’s the syntax:
Like a function reference itself, the
DYNAMIC-FUNCTIONfunction can appear anywhere in your procedure code where an expression of that data type could appear.The first parameter to
DYNAMIC-FUNCTIONis the name of the function to invoke. This procedure can be a quoted literal or an expression, such as a variable that evaluates to a valid function name.Following this, you can optionally include an
INhandlephrase to direct Progress to execute the function in a persistent procedure handle. In this case, thehandlemust be an actual field or variable name ofHANDLEdata type, not an expression.If the function itself takes any parameters, you pass those as additional parameters to
DYNAMIC-FUNCTION, in the same form that you would pass them to the function itself.
DYNAMIC-FUNCTIONgives you the flexibility to have code that can execute different function names depending on the situation, since thefunctionparameter can be a variable. You might have, for example, several different functions that do parallel work for different categories of data in a loop you’re iterating through. However, that is of perhaps limited value because all the functions you invoke must have the same signature.The most common use of
DYNAMIC-FUNCTIONis for one of two other reasons:
- If you want to reference a function without going to the trouble of defining a prototype for it, you can do this with
DYNAMIC-FUNCTION. Because Progress has no way of knowing what the name of the function is or its return type, it cannot look for a prototype for it and therefore does not give you an error as it would if you had a static reference to a function with no prior declaration. By the same token, it cannot provide you with any helpful warnings if your reference to the function is not valid.- If you want to invoke a function in a number of different persistent procedures, you can easily do this with
DYNAMIC-FUNCTIONsince the procedure handle to run it is part of the function reference, and not defined in the prototype. In this way, you can run a function in different persistent procedure instances depending on the circumstances. If each of those procedures represents an application object (such as a window, frame, browse, or query), then it can be very powerful to invoke the same function in different procedure handles representing those objects.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |